Detect blow in Mic and do something {iPhone SDK}

Posted by Momeks on Stack Overflow See other posts from Stack Overflow or by Momeks
Published on 2010-04-11T19:07:33Z Indexed on 2010/04/11 19:13 UTC
Read the original article Hit count: 774

Filed under:
|

Hi , i found this tutorial , and it's good , but doesn't work for me !

here is the code :

- (void)listenForBlow:(NSTimer *)timer {
    [recorder updateMeters];

    const double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;

    if (lowPassResults > 0.95)
        NSLog(@"Mic blow detected");
 //change the background color e.g !
}

in the console show me the nslog reseult like this (without any bowling !):

2010-04-11 23:32:27.935 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:27.965 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:27.995 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.026 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.055 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.086 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.115 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.145 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.175 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.205 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.236 MicBlow[2358:207] Mic blow detected

i change this value :

 if (lowPassResults < 0.95)

to

if (lowPassResults > 0.95)

so it seems work ! but doesn't chage anything , again if i put the background changing code the , my code change background but without any bowling !! what's the problem ?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about SDK